package com.cocotingo.snail;

import java.awt.Point;

public abstract class MouseEvent extends Event<java.awt.event.MouseEvent> {
	
	public static final int NOBUTTON = java.awt.event.MouseEvent.NOBUTTON;
	public static final int BUTTON1 = java.awt.event.MouseEvent.BUTTON1;
	public static final int BUTTON2 = java.awt.event.MouseEvent.BUTTON2;
	public static final int BUTTON3 = java.awt.event.MouseEvent.BUTTON3;

	public MouseEvent(java.awt.event.MouseEvent AWTEvent) {
		super(AWTEvent);
		AWTEvent.getClickCount();
		AWTEvent.getButton();
		AWTEvent.getPoint();
	}
	
	public int getClickCount() {
		return getAWTEvent().getClickCount();
	}
	
	public int getButton() {
		return getAWTEvent().getButton();
	}
	
	public Vector getPosition(final View view) {
		Point p = getAWTEvent().getPoint();
		Vector rst = new Vector(p.x, p.y);
		
		if (view == null) return new Vector(p.x, p.y);
		View[] hierarchy = view.getViewHierarchy();
		for (View v : hierarchy) {
			rst = v.transformPointFromSuperView(rst);
		}
		return rst;
	}
	
	abstract Vector getVelocity();
	
	public Vector getVelocity(View view) {
		Vector p2 = getVelocity();
		if (view == null) return p2;
		Vector p1 = new Vector();
		View[] hierarchy = view.getViewHierarchy();
		for (View v : hierarchy) {
			p2 = v.transformPointFromSuperView(p2);
			p1 = v.transformPointFromSuperView(p1);
		}
		p1.inverse();
		p2.increase(p1);
		return p2;
	}
	
}
